package analyse;

import java.math.BigDecimal;
import java.util.List;

import org.hibernate.Query;

import spring.SpringApplicationCtx;

import com.stock.StockQuery;
import com.stock.dao.Averline;

public class AverLineAlyz {
	public AverLineAlyz() {
	}
	
	public static boolean isUp(String number){
		StockQuery stockQuery = (StockQuery) SpringApplicationCtx.getCtx().getBean("StockQuery");
		boolean isUp = false;
		String sql = "from Averline where number = :number and dealDate>'2014-05-05' order by dealDate desc";
		Query query = stockQuery.getCurrentSession().createQuery(sql);
		List<Averline> list = query.setMaxResults(2).setString("number",number).list();
		
		BigDecimal last30Price = BigDecimal.ZERO;
		BigDecimal last15Price = BigDecimal.ZERO;
		for (Averline averline : list) {
			if(last30Price.compareTo(BigDecimal.ZERO)==0){
				last30Price = averline.getAver30();
				last15Price = averline.getAver15();
				continue;
			}else if(last30Price.compareTo(averline.getAver30())==0){
				isUp = last15Price.compareTo(averline.getAver15())>0;
			}else{
				isUp = last30Price.compareTo(averline.getAver30())>0;
			}
		}
		long t2 = System.currentTimeMillis();
		return isUp;
	}
}
